import Vue from 'vue'
import Tree from './tree'

function menulist (menuData, option) {
  if(!option) option = {}
  let el = option.el
  if (!el || el.length === 0) {
    el = '.menulist'
  }
  setTimeout(function () {
    /* eslint-disable no-new */
    new Vue({
      el,
      data: function () {
        return {
          menuData,
          open: option.open,
          openOnly: option.openOnly,
          indent: option.indent,
          arrow: option.arrow,
          arrowSize: option.arrowSize,
          arrowLeft: option.arrowLeft,
          animation: option.animation,
          eventArea: option.eventArea
        }
      },
      components: { Tree },
      template: '<Tree :menuData="menuData" :open="open" :openOnly="openOnly" :indent="indent" :arrow="arrow" :arrowLeft="arrowLeft" :arrowSize="arrowSize" :animation="animation" :eventArea="eventArea"></Tree>'
    })
  }, 0)
}

export default menulist
